<template>
	<mescroll-body ref="mescrollRef" @init="mescrollInit" :up="upOption" :down="downOption" @up="upCallback" @down="downCallback" >
		<giftmodel :listdata="listdata" :gifttype="type"></giftmodel>
	</mescroll-body>
</template>

<script>
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js"
	export default {
		mixins:[MescrollMixin],
		data(){
			return{
				listdata:[],
				type:'',
				downOption:{
					use:true,
					auto:true,
					autoShowLoading:true
				},
				upOption:{
					auto:false,
					noMoreSize: 4, 
					empty:{
						tip: '~ 搜索无数据 ~',
						btnText: ''
					},
					textLoading: "玩命加载中...",
					textNoMore: "-- 人家是有底线的 --",
				},
				seniorIcon: ['/static/image/dividebag.png', '/static/image/help.png', '/static/image/guarantee.png'],
			}
		},
		onLoad(Option) {
			this.type = Option.type
		},
		
		methods:{
			downCallback(e){
				this.mescroll.resetUpScroll()
			},
			
			upCallback(page){
				this.getinitdata(page.num).then(res => {
					console.log(res);
					this.mescroll.endSuccess(res.length);
					//设置列表数据
					if (page.num == 1) this.listdata = []; //如果是第一页需手动制空列表
					this.listdata = this.listdata.concat(res); //追加新数据 
				}).catch(error => {
					//联网失败, 结束加载
					this.mescroll.endErr();
					this.$ShowMsg('error::'+JSON.stringify(error))
					console.log(error)
				}) 
			},
			
			getinitdata(pages) {
				return new Promise((resolve, reject) => {
					this.$HttRequest({
						url: '/brand/show_lottery',
						param: {page: pages,type:this.type}
					}).then((res) => {
					//	console.log(res)
						if (res.status === 10000) {
							resolve(res.data.data);
						} else {
							this.$ShowMsg(res.message);
						}
					}).catch((error) => { 
						//异常错误
						reject(error.errMsg);
					})
				})
			}
			
		}
	}
</script>

<style lang="scss">
	
</style>
